<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://www.ufida.com/lfw" prefix="lfw" %>
<%@ taglib uri="http://www.ufida.com/uif" prefix="uif" %> 
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://www.ufida.com/lfwtool" prefix="lfwtool" %> 
<html>
	<head>
		<lfw:base/>
		<lfw:head/>
		<uif:import type="2"/>
		<uif:import pageId="<%= request.getParameter("pageId") %>"/>
		<script type='text/javascript' src='<%= "code/" + request.getParameter("pageId") + "?cache=1" %>'></script>
	</head>
	<body bottommargin="0" topmargin="0" leftmargin="0" rightmargin="0" scroll=no onload="pageBodyScript()" style="background:${lfwtool:getInfo("background")}">
		<lfw:pageModel className="nc.lfw.finance.set.ProxySetPageModel">
			<lfw:layout type="border">
				<lfw:layoutPanel position="top" height="26px">
					<lfw:menubar id="menubar1"/>
				</lfw:layoutPanel>
				<lfw:layoutPanel position="center">
					<lfw:grid id="userproxy_grid"/>
				</lfw:layoutPanel>
			</lfw:layout>
		</lfw:pageModel>
	</body>
</html>
<script>
/*
这个是模拟NC 流程平台的个人代理设置
*/
	function externalInit(){
		billUI.eventHandler.onBeforeBoSave = proxysave;
		var ds = getDataset("userproxy_ds");
		ds.onAfterDataChange = function(event){
			if(event.cellColIndex == this.nameToIndex("pk_workflow")){
				var strs = getService("webbx_common_service").getCorpByUserpk(event.currentValue);
				if(strs != null){
					var arr = eval(strs);
					ds.setValueAt(event.cellRowIndex, ds.nameToIndex("pk_corp"),arr[0],false);
					ds.setValueAt(event.cellRowIndex, ds.nameToIndex("pk_corp_mc"),arr[1],false);
				}
			}
		}
	}
	function afterPageInit() {
		//初始化 BillController
		var billController = new BillController("userproxy_ds", false, 1, null, null, null);
		billController.setHeadGrid("userproxy_grid");
		window.billUI = new ListUI(billController);
		
		var ds = getDataset("userproxy_ds");
		var loader = new DatasetLoader(ds);
		loader.setKeyValue(Dataset.MASTER_KEY);
		loader.setReturnFunc(returnFunc);
		loader.load();
		
	}
	function returnFunc(){
	 	ButtonManager.getInstance().setOperateStatus(IBillOperate.OP_NOTEDIT);
	 	ButtonManager.getInstance().updateButtons();
	 	var g = getComponent("userproxy_grid");
	 	g.setEditable(false);
	}
	
	function proxysave(){
		var ds = getDataset("userproxy_ds");
		var dsContent = ds.dataMap.get(ds.currentKey);
		if(dsContent != null){
			var records = dsContent.getRows(-1);
			if(records != null){
				for(var i = 0; i < records.length; i ++)
					if(records[i].state == DatasetRow.STATE_NRM)
						records[i].state = DatasetRow.STATE_UPD;
			}
		}
				
		var index = ds.nameToIndex('billtypes');
		var map = new HashMap();
		var count = 0;
		for(var k=0,len = ds.getRowCount(); k < len; k++){
			var row = ds.getRow(k);
			var v1 = row.getCellValue(index);
			if(v1 != null){
				count++;
				map.put(v1,k);
			}
		}
		var flag = false;
		if(count != map.size()){
			showMessageDialog("不能有重复的单据类型");
		}else
			flag = true;
		return flag;
	}
</script>